# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy


class NewhouseItem(scrapy.Item):
    house_name = scrapy.Field()  # 楼盘
    average_unit_price = scrapy.Field()  # 平均单价（元/m²）
    average_price = scrapy.Field()  # 平均总价（万/套）
    address = scrapy.Field()  # 位置
    site = scrapy.Field()  # 地址
    start_time = scrapy.Field()  # 开盘时间
    house_type = scrapy.Field()  # 楼盘类型
    title = scrapy.Field()
    area = scrapy.Field()
    price = scrapy.Field()

    def get_sql(self):
        sql = """INSERT INTO fang1(id, house_name, average_unit_price, average_price, address, site, start_time, house_type, title, area, price)""" \
              """ VALUES (NULL , %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
        data = [
            self["house_name"], self["average_unit_price"], self["average_price"], self["address"], self["site"],
            self["start_time"], self["house_type"],
            self["title"], self["area"], self["price"]
        ]
        return sql, data
